﻿import com.dmotiko.mirador.*
import com.dmotiko.general.*
import mx.transitions.easing.Regular;
import mx.transitions.Tween;
import mx.utils.Delegate;

class MiradorPreHome
extends MiradorSiteSection {
	private var loader:MiradorLoader;
	private var mcEdificios:MovieClip;
	private var checker:MovieClip;
	private var mcFade:MovieClip;
		
	function MiradorPreHome() {
		super( MiradorSite.getApp() );
		sName = MiradorSite.PREHOME;
		sectionChanged();
		if ( !MiradorSite.getApp() ) showSection();
	}
	
	private function initClip():Void {
		
	}
	
	
	public function childLoaded( e ):Void {
		if ( e.target instanceof MiradorLoader){
			loader = MiradorLoader(e.target);
			loader.addEventListener( BaseClipEvent.COMPLETE, Delegate.create(this, load_complete));
			
			var root:MovieClip = this;
			var tFade:Tween;
			checker = createEmptyMovieClip("checker", getNextHighestDepth());
			checker.onEnterFrame=function (){
				var p = ((_root.getBytesLoaded()/_root.getBytesTotal())*100);
				p = Math.round(p);
				if(tFade) tFade.stop();
				tFade = new Tween(root.mcFade, "_alpha", Regular.easeOut, root.mcFade._alpha, 100-p, 0.3, true );
				root.loader.setData(p);
				if ( p == 100) delete this.onEnterFrame;
			}
		}
	}
	
	private function load_complete( e ):Void {
		mcEdificios.play();
		this.gotoAndStop(3);
	}

	
	public function showSection() {
		if (bShowed) return;
		bShowed = true;
		this.gotoAndStop(2);
		showEnd();
	}
	
	public function hideSection() {
		if (!bShowed) return;
		bShowed = false;
		this.gotoAndStop(1);
		hideEnd();
	}
	
}